package com.itheima.bayueerhao;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Test02 {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(9998);
        Socket accept = ss.accept();
        InputStream is = accept.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("F:\\测试3\\头像.jpg"));
        byte[] bytes = new byte[8196];
        int lan;
        while ((lan=bis.read(bytes))!=-1){
            bos.write(bytes,0,lan);
        }

        //你好啊
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("上传成功");
        bw.newLine();
        bw.flush();
        bw.close();

        bos.flush();
        bis.close();
    }
}
